package net.oschina.team.note.core;

import net.oschina.team.note.bean.Notes;
import net.oschina.team.note.bean.NotesTemplate;
import net.oschina.team.note.route.PageRoutes;
import net.oschina.team.note.route.ServletRoutes;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.render.ViewType;
import com.sina.sae.util.SaeUserInfo;

public class CoreConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		me.add(new ServletRoutes());
		me.add(new PageRoutes());
	}

	@Override
	public void configPlugin(Plugins me) {
//SAE部署
//		String user = SaeUserInfo.getAccessKey();
//		String password = SaeUserInfo.getSecretKey();
//		C3p0Plugin c3p0 = new C3p0Plugin("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_stickynote", user, password);
		
//本地部署
//		String user = "root";
//		String password = "root";
//		C3p0Plugin c3p0 = new C3p0Plugin("jdbc:mysql://localhost:3306/stickynotes", user, password);
		
//mopaas@osc部署
		String dbname = "d35c05db060674b27aa832807416bad30";
		String user = System.getenv("MOPAAS_MYSQL16908_USER");
		String password = System.getenv("MOPAAS_MYSQL16908_PASSWORD");
		String MYSQL_SERVER_HOST = System.getenv("MOPAAS_MYSQL16908_HOST");
		String MYSQL_SERVER_PORT = System.getenv("MOPAAS_MYSQL16908_PORT");
		C3p0Plugin c3p0 = new C3p0Plugin("jdbc:mysql://"+MYSQL_SERVER_HOST+":"+MYSQL_SERVER_PORT+"/"+dbname, user, password);
		me.add(c3p0);
		
		ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql", c3p0);
		me.add(arpMysql);
		arpMysql.addMapping("notes", "id", Notes.class);
		arpMysql.addMapping("notes_template", "id", NotesTemplate.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub

	}

}
